package com.pangu.event.publish;

import com.pangu.message.constant.MessageEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author Linbizhao
 * @description: 消息事件发送方
 * @since 2023/11/23 15:04
 */
@Slf4j
@Component
public class MessageEventSender {

    @Autowired
    private ApplicationContext applicationContext;

    public Boolean sendMessageEvent(com.pangu.interfaces.dto.event.MessageEvent event) {
        String type = event.getType();
        boolean sendStatus = Boolean.TRUE;
        switch (MessageEvent.getEnumByType(type)) {
            case changeStatus:
                applicationContext.publishEvent(new StatusChangeEvent(event));
                break;
            default:
                sendStatus = false;
        }
        return sendStatus;
    }
}
